<?php
namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\download\Download;
use yii\base\Object;
use yii\data\Pagination;

/*
*	模块：下载
*	作者：班未军
*	时间：2015-11-28
*/

class DownloadController extends Controller{
	//下载首页展示
	public function actionIndex($course_id = 0,$cate_id = 0){
	    $model = new Download;
		return $this->render('index',[
		                  'course'=>$model->getCourse(),
		                  'cate'=>$model->getCategory(),
		                  'lists'=>$model->getSoftinfo($course_id,$cate_id)
		              ]);
	}
	
	//下载相关课程展示
	public function actionCourse(){
        if (Yii::$app->request->isAjax){
	       $id = intval(Yii::$app->request->post('soft_id'));
	       $model = new Download;
	       $result = $model->getSoftcourse($id);
	       echo json_encode($result);
        }
	}
	
	//下载软件
	public function actionDownloadsoft() {
        if (Yii::$app->request->isAjax){
	       $model = new Download;
	       $result = $model -> downFile(Yii::$app->request->post('soft_id'));
	       if($result['data']==4) {
	           $this->redirect(['download/downsoft','soft_id'=>Yii::$app->request->post('soft_id')]);
	       }
	       echo json_encode($result);
        }
	}
	
	//窗体下载
	public function actionDownsoft() {
	    $model = new Download;
	    $result = $model -> downloadSoft(Yii::$app->request->get('soft_id'));
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
?>